<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<body>
		<form enctype="multipart/form-data" id="templateUploadForm" name="templateUploadForm">
			<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
			<table width="100%">
				<tr>
					<td align="left">
						<label>
							Name the template:
						</label>
					</td>
					<td align="right">
						<input dojoType="dijit.form.TextBox" id="templateName" name="name" />
					</td>
				</tr>
				<tr>
					<td align="left"">
						<label>
							Choose report type:
						</label>
					</td>
					<td align="right">
						<select dojoType="dijit.form.ComboBox" id="templateType" name="type">
							<option>Users</option>
							<option>Projects</option>
							<option>Instruments</option>
						</select>
					</td>
				</tr>
				<tr>
					<td align="left">
						Pick template:
					</td>
					<td align="right">
						<input type="file" name="templateFile" id="templateFile" />
					</td>
				</tr>
				<tr>
					<td colspan=2 align="right">
						<button dojoType="dijit.form.Button">
							Cancel 
							<script event="onClick" args="event" type="dojo/method">
								dijit.byId( "templateDialog").destroyRecursive( );
							</script>	
						</button>
						<button dojoType="dijit.form.Button">
							Upload and Save
							<script event="onClick" args="event" type="dojo/method">
								dojo.io.iframe.send( {
									method : "post",
									timeoutSeconds: 15, 
									contentType: "multipart/form-data",
									url 	: "/FinalProject/app/xsltStorageManagement.xsl?xsltStorageOp=xslt_insert",
									form	: "templateUploadForm",
									load 	: function( data, ioArgs) {
										if ( data == "ERROR") {
											dijit.byId('toaster').setContent('Backend error. Could not upload report template.', 'fatal');
										    dijit.byId('toaster').show();							
											return;
										}
								        dijit.byId('toaster').setContent('Report template uploaded successefuly.', 'fatal');
								        dijit.byId('toaster').show();
										dijit.byId( "reportGeneration").refresh( );																		
										dijit.byId( "templateDialog").destroyRecursive( );
									},
									error	: function( data) {
										dijit.byId('toaster').setContent('Backend error. Could not upload report template.', 'fatal');
									    dijit.byId('toaster').show();							
										return;
									}
								});
							</script>
						</button>
					</td>					
				</tr>
			</table>
		</form>	
	</body>
</html>